package com.example.projectcode.controller.Teacher;
import com.example.projectcode.model.Choice;
import com.example.projectcode.model.Comprehensive;
import com.example.projectcode.result.Result;
import com.example.projectcode.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "试卷生成接口")
@RestController
@RequestMapping(value = "/teacher/examPaperGeneration")
public class ExamPaperGenerationManagement {

    @Autowired
    private TestService testService;

    @Autowired
    private SubjectService subjectService;

    @Autowired
    private ChapterService chapterService;

    @Autowired
    private TestPointService testPointService;

    @Autowired
    private ChoiceService choiceService;

    @Autowired
    private TestchoiceService testchoiceService;

    @Autowired
    private ComprehensiveService comprehensiveService;

    @Autowired
    private TestcomprehensiveService testcomprehensiveService;

    @ApiOperation("创建试卷")
    @GetMapping(value = "/makeTestPaper/{testName}/{limitTime}")
    public Result makeTestPaper(@PathVariable String testName, @PathVariable Integer limitTime){
         Integer testId = testService.makePaper(testName,limitTime);
        Map<String,Object> map = new HashMap<>();
        map.put("testId",testId);
          //返回试卷id
          return Result.ok(map);
    }
/* ------------------------------------添加选择题 ----------------------------------*/
    @ApiOperation("选择科目")
    @GetMapping(value = "/addChoiceBySubject")
    public Result addChoiceBySUbject(){
        return Result.ok(subjectService.selectAllSubject()) ;
    }

    @ApiOperation("选择章节")
    @GetMapping(value = "/addChoiceByChapter/{SubjectId}")
    public Result addChoiceByChapter(@PathVariable Integer SubjectId){
        return Result.ok(chapterService.selectAllChapterBySubid(SubjectId)) ;
    }

    @ApiOperation("选择考点")
    @GetMapping(value = "/addChoiceByTestPoint/{ChapterId}")
    public Result addChoiceByTestPoint(@PathVariable Integer ChapterId){
        return Result.ok(testPointService.selectAllTestPointByChapid(ChapterId)) ;
    }

    @ApiOperation("选择选择题题目")
    @GetMapping(value = "/addChoice/{TestPointId}")
    public Result addChoice(@PathVariable Integer TestPointId){
        List<Choice> choiceList = choiceService.selectCHoiceByTestPointId(TestPointId);
        return Result.ok(choiceList) ;
    }

    @ApiOperation("根据试卷id添加选择题")
    @GetMapping(value = "/addChoiceBytestId/{testId}/{choiceId}/{score}")
    public Result addChoiceBytestId(@PathVariable Integer testId,
                                    @PathVariable Integer choiceId,
                                    @PathVariable Integer score){
        int result = testchoiceService.addchoice(testId,choiceId,score);
        if (result>0){
            return Result.ok(result);
        }else {
            return Result.fail();
        }
    }

    /* ------------------------------------添加综合题 ----------------------------------*/


    @ApiOperation("选择科目")
    @GetMapping(value = "/addComprehensiveBySubject")
    public Result addComprehensiveBySUbject(){
        return Result.ok(subjectService.selectAllSubject()) ;
    }

    @ApiOperation("选择章节")
    @GetMapping(value = "/addComprehensiveByChapter/{SubjectId}")
    public Result addComprehensiveByChapter(@PathVariable Integer SubjectId){
        return Result.ok(chapterService.selectAllChapterBySubid(SubjectId)) ;
    }

    @ApiOperation("选择考点")
    @GetMapping(value = "/addComprehensiveByTestPoint/{ChapterId}")
    public Result addComprehensiveByTestPoint(@PathVariable Integer ChapterId){
        return Result.ok(testPointService.selectAllTestPointByChapid(ChapterId)) ;
    }

    @ApiOperation("选择综合题题目")
    @GetMapping(value = "/addComprehensive/{TestPointId}")
    public Result addComprehensive(@PathVariable Integer TestPointId){
        List<Comprehensive> comprehensiveList = comprehensiveService.selectComprehensiveByTestPointId(TestPointId);
        return Result.ok(comprehensiveList) ;
    }


    @ApiOperation("根据试卷id添加综合题")
    @GetMapping(value = "/addComprehensiveBytestId/{testId}/{cpId}/{score}")
    public Result addComprehensiveBytestId(@PathVariable Integer testId,
                                    @PathVariable Integer cpId,
                                    @PathVariable Integer score){
        int result = testcomprehensiveService.addComprehensive(testId,cpId,score);
        if (result>0){
            return Result.ok(result);
        }else {
            return Result.fail();
        }
    }











}
